:- module(eurostat,[]).


:- use_module('toc/toc_mapping').
:- use_module(ns).

dir_triple(Dir,Triple) :-
	toc_mapping:directory(Dir,URI),
	atom_concat('data/',Id,Dir),
	t_record:t_record('toc/table_of_contents.tsv',[Desc,Id,_,LastUpdate,DataStart,DataEnd,_Values,_Rows,_Cols,Restricted]),
	toc_mapping:parse_desc(Desc,_,Label),
	Triples = 
		[
			rdf(URI,rdf:type,riese:'Dataset')
		,	rdf(URI,dc:title,literal(Label))
		,	rdf(URI,rdfs:label,literal(Label))
		,	rdf(URI,riese:last_update(LastUpdate))
		,	rdf(URI,riese:data_start,literal(DataStart))
		,	rdf(URI,riese:data_end,literal(DataEnd))
		,	rdf(URI,riese:access_type,literal(Restricted))
		],
	member(Triple,Triples).
dir_triple(Dir,rdf(URI1,skos:narrower,URI2)) :-
	toc_mapping:directory(Dir,URI1),
	p2r_entailment:rdf(URI1,skos:narrower,URI2).
dir_triple(Dir,rdf(URI1,skos:broader,URI2)) :-
	toc_mapping:directory(Dir,URI1),
	p2r_entailment:rdf(URI1,skos:broader,URI2).

dir_triple(Dir2,Triple) :-
	tsv_mapping:directory(Dir,URI),
	concat_atom(List,'/',Dir),
	id(List,ID),
	format(atom(File),'data/all_data/~w.tsv',ID),
	tsv:value(File,Dimensions,IndiceDim,Indice,Value,Flag),
	tsv_mapping:dimension_id(Dimensions,DimID),
	tsv_mapping:format_label(Id,Dimensions,Indice,IndiceDim,Label),
	ns:item_ns(NS),
	atom_concat(NS,ID,Dataset),
	Triples = 
		[
			rdf(URI,rdf:value,literal(Value))
		,	rdf(URI,riese:indice,literal(Indice))
		,	rdf(URI,riese:indice_dim,literal(IndiceDim))
		,	rdf(URI,riese:dataset,Dataset)
		].



id([data,H|_],H):-!.
id([_|T],H) :- id(T,H).



